/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.net.greenet.common.policy_service;


import cn.net.greenet.db.HibernateUtil;
import cn.net.greenet.db.bean.Policyrepositoryinstance;
import com.ambimmort.app.framework.uitls.Application;
import com.ambimmort.prserver.repository.webservice.PRMWebService;
import org.hibernate.Session;

import java.util.List;

/**
 *
 * @author 定巍
 */
public class PolicySupport {

    PRMWebService api = null;

    private static PolicySupport instance = null;

    public static PolicySupport getInstance() {
        if (instance == null) {
            instance = new PolicySupport();
        }
        return instance;
    }

    private void init(){
        Session session = HibernateUtil.getSessionFactory().openSession();
        List l = session.createQuery("FROM Policyrepositoryinstance").list();
        Policyrepositoryinstance bean = null;
        for (int i = 0; i < l.size(); i++) {
            bean = (Policyrepositoryinstance) l.get(i);
            getApi().createRepository(bean.getPolicyrepositorytype().getMessageType(), bean.getInstanceName());
        }
        session.close();
    }
    
    private PolicySupport() {
        api = (PRMWebService) Application.getBean("prmSupport");
    }

    public void refresh() {


    }

    public PRMWebService getApi() {
        return api;
    }

    
}
